package com.googlecode.bip.entity.impl;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import com.googlecode.bip.entity.IUserReferentComments;

/**
 * Default implementation of {@link IReferentUserComments}
 *
 * @author Claude CHOISNET
 */
public class UserReferentComments
    implements Serializable, IUserReferentComments
{
    private static final long serialVersionUID = 2L;
    private int         iduser;
    private int         idreferent;
    private int         idfrom;
    private Timestamp   commentDate;
    private String      comment;

    public UserReferentComments()
    {
        // empty
    }

    public UserReferentComments set( ResultSet rSet )
        throws SQLException
    {
        this.iduser         = rSet.getInt( "iduser" );
        this.idreferent     = rSet.getInt( "idreferent" );
        this.idfrom         = rSet.getInt( "idfrom" );
        this.commentDate    = rSet.getTimestamp( "commentDate" );
        this.comment        = rSet.getString( "comment" );

        return this;
    }

    @Override
    public int getUserId()
    {
        return iduser;
    }

    @Override
    public int getReferentId()
    {
        return idreferent;
    }

    @Override
    public int getFromId()
    {
        return idfrom;
    }

    @Override
    public Timestamp getCommentDate()
    {
        return commentDate;
    }

    @Override
    public String getComment()
    {
        return comment;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        return "UserReferentComments [iduser=" + iduser + ", idreferent="
                + idreferent + ", idfrom=" + idfrom + ", commentDate="
                + commentDate + ", comment=" + comment + "]";
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((comment == null) ? 0 : comment.hashCode());
        result = prime * result
                + ((commentDate == null) ? 0 : commentDate.hashCode());
        result = prime * result + idfrom;
        result = prime * result + idreferent;
        result = prime * result + iduser;
        return result;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals( Object obj )
    {
        if( this == obj ) {
            return true;
        }
        if( obj == null ) {
            return false;
        }
        if( !(obj instanceof UserReferentComments) ) {
            return false;
        }
        UserReferentComments other = (UserReferentComments)obj;
        if( comment == null ) {
            if( other.comment != null ) {
                return false;
            }
        } else if( !comment.equals( other.comment ) ) {
            return false;
        }
        if( commentDate == null ) {
            if( other.commentDate != null ) {
                return false;
            }
        } else if( !commentDate.equals( other.commentDate ) ) {
            return false;
        }
        if( idfrom != other.idfrom ) {
            return false;
        }
        if( idreferent != other.idreferent ) {
            return false;
        }
        if( iduser != other.iduser ) {
            return false;
        }
        return true;
    }
}
